x = int(input())
x1=x
d = x1%10
c = x1//10%10
b = x1//100%10
a = x1//1000%10
max_prost = 0
k1 = b * 100 + c * 10 + d
q= k1
count = 0
for i in range( 1 , q+ 1):
    if q % i == 0:
      count += 1
if count == 2:
    q = x1
    if k1 > max_prost:
      max_prost = k1
k2 = a * 100 + b * 10 + c
w = k2
count = 0
for i in range(1 , w + 1):
    if w % i == 0:
      count += 1
if count == 2:
    w = x
    if k2 > max_prost:
       max_prost = k2 
k3 = c * 10 + d
m = k3
count = 0
for i in range(1 , m + 1):
    if m % i == 0:
      count += 1
if count == 2:
    m = x
    if k3 > max_prost:
       max_prost = k3
k4 = b * 10 + c
r= k4
count = 0
for i in range(1 , r + 1):
    if r % i == 0:
      count += 1
if count == 2:
    r = x
    if k4 > max_prost:
       max_prost = k4
k5 = a * 10 + b
o = k5
count = 0
for i in range(1 , o + 1):
    if o % i == 0:
      count += 1
if count == 2:
    o = x
    if k5> max_prost:
       max_prost = k5
k6 = a
n = k6
count = 0
for i in range(1 , n + 1):
    if n % i == 0:
      count += 1
if count == 2:
    n = x
    if k6 > max_prost:
       max_prost = k6
k7 = b
t = k7
count = 0
for i in range(1 , t + 1):
    if t % i == 0:
      count += 1
if count == 2:
    t = x
    if k7 > max_prost:
       max_prost = k7
k8 = c
f = k8
count = 0
for i in range(1 , f + 1):
    if f % i == 0:
      count += 1
if count == 2:
    f = x
    if k8 > max_prost:
       max_prost = k8
k9 = d
l = k9
count = 0
for i in range(1 , l + 1):
    if l % i == 0:
      count += 1
if count == 2:
    l = x
    if k9 > max_prost:
       max_prost = k9
k10 = a * 1000 + b * 100 + c * 10 + d
f = k10
count = 0
for i in range(1 ,  + 1):
    if f % i == 0:
      count += 1
if count == 2:
    f = x
    if k10 > max_prost:
       max_prost = k10
if len(str(x))!=4:
    max_prost = 0
if x<0:
    max_prost = 0
print(max_prost)
